/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**
 *  @author     Andrew Wei
 *  @portfolio  http://andrewwei.mu
 *
 *  ©2012 Andrew Wei
 *
 *  This software is released under the MIT License:
 *  http://www.opensource.org/licenses/mit-license.php
 **++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
package com.ghoztudios.helper
{
    import flash.utils.Dictionary;
    import flash.utils.getQualifiedClassName;
    import flash.utils.getQualifiedSuperclassName;

    /**
     * Static helper class with utility functions.
     *
     * @langversion     3.0
     * @playerversion   Flash 10.3.183.20
     */
    public class Handyman
    {
        private static const ID:String = 'com.ghoztudios.helper.Handyman';


        // Constants
        /**
         * String vector of known file extensions.
         *
         * @langversion     3.0
         * @playerversion   Flash 10.3.183.20
         */
        private static const FILE_EXTENSIONS:Vector.<String> = Vector.<String>(['swf', 'html', 'xml']);


        // Public Methods
        /**
         * Gets the class name of the object without package details.
         *
         * @param   $object
         * @return  Class name of the object without package details.
         * @langversion     3.0
         * @playerversion   Flash 10.3.183.20
         */
        public static function getClassName($object:Object):String
        {
            var qualifiedClassName:String = getQualifiedClassName($object);
            var index:int                 = qualifiedClassName.indexOf(':') + 1;
            var className:String          = qualifiedClassName.substr(index, qualifiedClassName.length - index);

            return(className);
        }

        /**
         * Gets the name of the superclass of the object without package details.
         *
         * @param   $object
         * @return  Name of superclass of the object without package details.
         * @langversion     3.0
         * @playerversion   Flash 10.3.183.20
         */
        public static function getSuperclassName($object:Object):String
        {
            var qualifiedSuperclassName:String = getQualifiedSuperclassName($object);
            var index:int                      = qualifiedSuperclassName.indexOf(':') + 2;
            var superclassName:String          = qualifiedSuperclassName.substr(index, qualifiedSuperclassName.length - index);

            return(superclassName);
        }

        /**
         * Gets the size of the dictionary.
         *
         * @param   $dictionary
         * @return  Size of dictionary.
         * @langversion     3.0
         * @playerversion   Flash 10.3.183.20
         */
        public static function getDictionarySize($dictionary:Dictionary):int
        {
            var count:int = 0;

            for (var i:* in $dictionary)
            {
                count;
            }

            return count;
        }

        /**
         * Determines if a string is a file path.
         *
         * @param   $string
         * @return  True if string is a file path, false otherwise.
         * @langversion     3.0
         * @playerversion   Flash 10.3.183.20
         */
        public static function isFilePath($string:String):Boolean
        {
            var exIndex:int = $string.indexOf('.');

            if (exIndex == -1)
                return false;

            var extension:String = $string.substring(exIndex + 1, $string.length);

            if (FILE_EXTENSIONS.indexOf(extension) != -1)
                return true;
            else
                return false;
        }

        /**
         * Toggles a boolean property.
         *
         * @param   $flag
         * @langversion     3.0
         * @playerversion   Flash 10.3.183.20
         */
        public static function toggle($flag:Boolean):void
        {
            $flag = !$flag;
        }
    }
}
